home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form StockForm
- Caption = "Stocks"
- ClientHeight = 3990
- ClientLeft = 1875
- ClientTop = 1665
- ClientWidth = 5190
- Height = 4680
- Left = 1815
- LinkTopic = "Form1"
- ScaleHeight = 3990
- ScaleWidth = 5190
- Top = 1035
- Width = 5310
- Begin VB.TextBox FPSText
- Height = 285
- Left = 1440
- TabIndex = 5
- Text = "10"
- Top = 3600
- Width = 375
- End
- Begin VB.CommandButton CmdStart
- Caption = "Start"
- Default = -1 'True
- Height = 495
- Left = 2160
- TabIndex = 1
- Top = 3480
- Width = 855
- End
- Begin VB.PictureBox GraphPict
- AutoRedraw = -1 'True
- Height = 3375
- Left = 0
- ScaleHeight = -100
- ScaleLeft = 0.5
- ScaleMode = 0 'User
- ScaleTop = 100
- ScaleWidth = 10.75
- TabIndex = 0
- Top = 0
- Width = 5175
- End
- Begin VB.Label Label1
- Caption = "Frames per second:"
- Height = 255
- Index = 1
- Left = 0
- TabIndex = 4
- Top = 3600
- Width = 1455
- End
- Begin VB.Label DayLabel
- BorderStyle = 1 'Fixed Single
- Height = 255
- Left = 4800
- TabIndex = 3
- Top = 3600
- Width = 375
- End
- Begin VB.Label Label1
- Caption = "Day:"
- Height = 255
- Index = 0
- Left = 4440
- TabIndex = 2
- Top = 3600
- Width = 375
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "StockForm"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Const NUM_STOCKS = 10
- Const NUM_FRAMES = 100
- Dim Data(1 To NUM_FRAMES, 1 To NUM_STOCKS) As Integer
- Dim Playing As Boolean
- ' ************************************************
- ' Generate some random data.
- ' ************************************************
- Sub InitData()
- Dim stock As Integer
- Dim frame As Integer
- ' Set the initial values between 30 and 70.
- For stock = 1 To NUM_STOCKS
- Data(1, stock) = Int(41 * Rnd + 30)
- Next stock
- ' Make values for the other frames.
- ' Each value is up to +/- 5 different than the
- ' previous value for the same stock.
- For frame = 2 To NUM_FRAMES
- For stock = 1 To NUM_STOCKS
- Data(frame, stock) = _
- Data(frame - 1, stock) + _
- Int(11 * Rnd - 5)
- If Data(frame, stock) < 0 Then _
- Data(frame, stock) = 5
- If Data(frame, stock) > 100 Then _
- Data(frame, stock) = 95
- Next stock
- Next frame
- End Sub
- ' ************************************************
- ' Start the animation.
- ' ************************************************
- Private Sub CmdStart_Click()
- If Playing Then
- Playing = False
- CmdStart.Caption = "Stopped"
- CmdStart.Enabled = False
- Else
- CmdStart.Caption = "Stop"
- Playing = True
- InitData
- PlayData
- Playing = False
- CmdStart.Caption = "Start"
- CmdStart.Enabled = True
- End If
- End Sub
- ' ************************************************
- ' Play the animation.
- ' ************************************************
- Sub PlayData()
- Dim mpf As Long ' Milliseconds per frame.
- Dim frame As Integer
- Dim stock As Integer
- Dim next_time As Long
- Dim old_style As Integer
- ' Set FillStyle to vbSolid.
- old_style = GraphPict.FillStyle
- GraphPict.FillStyle = vbSolid
- ' See how fast we should go.
- If Not IsNumeric(FPSText.Text) Then _
- FPSText.Text = "10"
- mpf = 1000 \ CLng(FPSText.Text)
- ' Draw the background.
- '
- ' Note that we must cover all of the background
- ' so it becomes part of the image. Then Cls
- ' will restore it.
- GraphPict.Line (0, 0)-(NUM_STOCKS + 1.25, 50), RGB(128, 128, 128), BF
- GraphPict.Line (0, 50)-(NUM_STOCKS + 1.25, 100), GraphPict.BackColor, BF
- ' Make the picture a permanent part of the
- ' background.
- GraphPict.Picture = GraphPict.Image
- ' Start the animation.
- next_time = GetTickCount()
- For frame = 1 To NUM_FRAMES
- If Not Playing Then Exit For
-
- ' Draw the graph.
- GraphPict.Cls
- For stock = 1 To NUM_STOCKS
- If Data(frame, stock) > 50 Then
- GraphPict.Line (stock, 0)-(stock + 0.75, 50), vbRed, BF
- GraphPict.Line (stock, 50)-(stock + 0.75, Data(frame, stock)), vbGreen, BF
- Else
- GraphPict.Line (stock, 0)-(stock + 0.75, Data(frame, stock)), vbRed, BF
- End If
- Next stock
- GraphPict.Line (0, 50)-(NUM_STOCKS + 1.25, 50), vbBlack, BF
- DayLabel.Caption = Format$(frame)
-
- ' Wait until it's time for the next frame.
- next_time = next_time + mpf
- WaitTill next_time
- Next frame
- ' Restore the old FillStyle.
- GraphPict.FillStyle = old_style
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- End
- End Sub
- Private Sub mnuFileExit_Click()
- Unload Me
- End Sub
-